package com.lestar.htmlparser;

import org.htmlparser.Attribute;
import org.htmlparser.Node;
import org.htmlparser.Tag;
import org.htmlparser.filters.HasAttributeFilter;

/**
 * Created by Ray on 2016/10/11.
 */

public class HasRegexAttrFilter extends HasAttributeFilter {

    public HasRegexAttrFilter(String attribute, String value) {
        super(attribute, value);
    }

    @Override
    public boolean accept(Node node) {
        Tag tag;
        Attribute attribute;
        boolean ret;

        ret = false;
        if (node instanceof Tag) {
            tag = (Tag) node;
            attribute = tag.getAttributeEx(mAttribute);
            ret = null != attribute;
            if (ret && (null != mValue))
                ret = attribute.getValue().matches(mValue);
        }

        return (ret);
    }
}
